//
//  AFGetData.h
//  MVideo
//
//  Created by Lin Eidan on 14-4-15.
//  Copyright (c) 2014年 taomee. All rights reserved.
//

@class VideoObj;


#import <Foundation/Foundation.h>
#import "AFHTTPRequestOperationManager.h"
#import "AFDownloadRequestOperation.h"
#import "AFHTTPSessionManager.h"
#import "AFNetworkReachabilityManager.h"

//iOS6
typedef void (^completionOperationBlock) (AFHTTPRequestOperation *operation,id responseObj, BOOL isSuccess);  //void 返回值，后面的为参数

//iOS7
typedef void (^completionTaskBlock) (NSURLSessionDataTask *task, id responseObj, BOOL isSuccess);  //void 返回值，后面的为参数

//public
typedef void (^completionBlock) (id responseObj, BOOL isSuccess);  //void 返回值，后面的为参数
typedef void (^dataBodyBlock)( id<AFMultipartFormData> formData );  //post数据


@interface AFGetData : NSObject <NSURLSessionDelegate>

//public
@property (strong, nonatomic) AFNetworkReachabilityManager *networkStateManager;

-(id)startGet:(NSString *)url andResultIsJSON:(BOOL)iSJSON andRequestCompletion:(completionBlock)block;
-(id)startPost:(NSString *)url andInfo:(NSDictionary *)infoDic andDataBodyBlock:(dataBodyBlock)dataBlock andRequestCompletion:(completionBlock)block;

/*上传图片
 UIImage *image1 = [UIImage imageNamed:@"about_app"];
 NSData *imageData = UIImageJPEGRepresentation(image1,0.5);
 [formData appendPartWithFileData:imageData name:@"image1" fileName:@"image1.jpg"  mimeType:@"image/jpeg"];
*/

+ (AFGetData *)sharedInstance;

-(void)removeAllGetAndPostRequest;

-(BOOL)theNetworkTypeIsNone; //没网络就为YES
-(BOOL)theNetworkTypeIs3G;
-(BOOL)theNetworkTypeIsWifi;


-(void)initSDWebImage:(NSString *)url andTrueImageView:(UIImageView *)trueImageView andPlaceholderImage:(UIImage *)placeholder;
-(BOOL)initSDWebImageThatLaunchAction:(NSString *)url andTrueImageView:(UIImageView *)trueImageView;

-(id)convertDataToJsonFromData:(NSData *)data;


//iOS6
@property (strong, nonatomic) AFHTTPRequestOperationManager *operationManager;
-(AFHTTPRequestOperation *)startGet:(NSString *)url andResultIsJSON:(BOOL)iSJSON andCompletion:(completionOperationBlock)block;
-(AFHTTPRequestOperation *)startPost:(NSString *)url andInfo:(NSDictionary *)infoDic andDataBodyBlock:(dataBodyBlock)dataBlock andCompletion:(completionOperationBlock)block;

//iOS7 background
@property (strong, nonatomic) AFHTTPSessionManager *sessionHttpManager;
-(NSURLSessionDataTask *)startGet:(NSString *)url andResultIsJSON:(BOOL)iSJSON andTaskCompletion:(completionTaskBlock)block;
-(NSURLSessionDataTask *)startPost:(NSString *)url andInfo:(NSDictionary *)infoDic andDataBodyBlock:(dataBodyBlock)dataBlock andTaskCompletion:(completionTaskBlock)block;

@end
